package com.zgm.ch04._2_2_2;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

public class DestructBean implements InitializingBean, DisposableBean {
	private InputStream is = null;
	private String filePath = null;
	
	

	public void afterPropertiesSet() throws Exception {
		System.out.println("初始化开始...");
		
		Assert.notNull(this.filePath, "filePath 必须设置！");
		
//		new File(this.filePath).createNewFile();
		File file = new File(this.filePath);
		boolean isCreate = file.createNewFile();
		this.is = new FileInputStream(this.filePath);
	}
	
	public void destroy() throws Exception {
		System.out.println("销毁工作进行中。。。");
		
		if(this.is != null){
			try {
				this.is.close();
				this.is = null;
				new File(this.filePath).delete();
			} catch (IOException e) {
				System.out.println("一个IOEception发生了！");
			}
		}
	}

	public final void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	

}
